package top.fullj.chase.internal;

import java.io.PrintWriter;
import java.io.StringWriter;

import top.fullj.chase.spi.VirtLog;

final class ConsoleLog implements VirtLog {

    @Override
    public void enter(String message) {
        System.out.println(message);
    }

    @Override
    public void ret(String message) {
        System.out.println(message);
    }

    @Override
    public void thrown(String message, Throwable tr) {
        System.out.println(message + ": " + getStackTrace(tr));
    }

    private static String getStackTrace(Throwable tr) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        tr.printStackTrace(pw);
        pw.flush();
        return sw.toString();
    }

}
